home *** CD-ROM | disk | FTP | other *** search
- head 1.2;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.2
- date 87.01.06.12.57.38; author dudek; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 86.01.10.15.05.04; author dudek; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.2
- log
- @*New* and *improved* - use '!' syntax for input addresses instead of '@@' -gd
- @
- text
- @/*
- * pathsend dest-host user
- */
-
- #include <stdio.h>
- #include <ctype.h>
-
- typedef struct {
- char *dptr;
- int dsize;
- } datum;
-
- /* From sendmail sysexits.c */
- #define ERR_USAGE 64
- #define ERR_DATAERR 65
- #define ERR_NOHOST 68
- #define ERR_UNAVAILABLE 69
- #define ERR_SOFTWARE 70
- #define ERR_OSERR 71
- #define ERR_OSFILE 72
-
- extern datum fetch();
-
- #define PATHALIASES "/usr/lib/pathaliases"
- #define SENDMAIL "/usr/lib/sendmail"
-
- #define MAXRECIPIENTS 100+3
-
- char *sendmail = SENDMAIL;
-
- main(argc, argv)
- char *argv[];
- {
- datum key, content;
- int i, pid, verbose = 0, debug = 0, index, saveindex;
- register char *bp;
- char *user, *from = ((char *) NULL), *mkstring(), *findhost();
- char dest[2048], buf[2048];
- char *sendargv[MAXRECIPIENTS];
-
- for (argc--, argv++; argc && **argv == '-'; argc -= i, argv += i) {
- i = 1;
- while (*++*argv) {
- switch (**argv) {
- case 'd':
- debug++;
- break;
- case 'f':
- if (argc <= i)
- done(ERR_USAGE,"Not enough args for '-f'\n");
- from = argv[i++];
- break;
- case 'm':
- if (argc <= i)
- done(ERR_USAGE,"Not enough args for '-m'\n");
- sendmail = argv[i++];
- break;
- case 'v':
- verbose++;
- break;
- default:
- fprintf(stderr,"Unknown switch '-%c'\n",**argv);
- done(ERR_USAGE,
- "Usage: pathsend [-dv] [-m mailer] [host!...!user]\n");
- }
- }
- }
-
- if (dbminit(PATHALIASES) < 0)
- done(ERR_SOFTWARE,"pathsend: can't dbminit %s\n",PATHALIASES);
-
- index = 0;
- sendargv[index++] = "pathsendmail";
-
- if (verbose)
- sendargv[index++] = "-v";
-
- if (from) {
- sendargv[index++] = "-f";
- sendargv[index++] = from;
- }
-
- saveindex = index;
- for (; argc > 0; argv++, argc--) {
-
- /* Default pathalias address is original address */
- strcpy(buf,*argv);
-
- /* Try and pathalias each host in left-to-right order,
- * until a pathalias-able host is found
- */
- for (user = *argv; user = findhost(user,dest);) {
-
- key.dptr = dest;
- key.dsize = strlen(dest) + 1;
- content = fetch(key);
-
- if (content.dptr != 0) {
- sprintf(buf, content.dptr, user);
- break;
- }
- }
-
- /* Make sure there is no recursive pathaliasing */
- strcat(buf,";nopath");
-
- sendargv[index++] = mkstring(buf);
- }
-
- if (index != saveindex) {
- sendargv[index] = (char *)NULL;
- if (debug) {
- printf("sending to < ");
- for (i = saveindex; i < index; i++)
- printf("%s ",sendargv[i]);
- printf(">\n");
- } else {
- switch (pid = fork()) {
- case -1:
- done(ERR_OSERR,"pathsend: can't fork\n");
- case 0:
- execv(sendmail,sendargv);
- done(ERR_OSFILE,"pathsend: can't execl %s\n",SENDMAIL);
- default:
- while (wait((int *) NULL) != pid);
- break;
- }
- }
- }
-
- done(0);
- }
-
- done(status,str,a,b,c,d,e,f)
- int status;
- char *str;
- {
- if (status)
- fprintf(stderr,str,a,b,c,d,e,f);
- exit(status);
- }
-
- char *
- mkstring(string)
- char *string;
- {
- char *str, *malloc();
-
- if ((str = malloc(strlen(string)+1)) == (char *)NULL)
- done(ERR_SOFTWARE,"can't malloc for destination\n");
- strcpy(str,string);
- return(str);
- }
-
- char *
- findhost(user,dest)
- char *user,*dest;
- {
- char *newuser,*index();
-
- if ((newuser = index(user,'!')) == NULL)
- return((char *) NULL);
-
- sscanf(user,"%[^!]!",dest);
- return(++newuser);
- }
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d37 2
- a38 2
- char *dest, *user, *from = ((char *) NULL), *mkstring();
- char buf[2048];
- d64 1
- a64 1
- "Usage: pathsend [-dv] [-m mailer] [user@@dest-host...]\n");
- d86 2
- a87 2
- user = *argv;
- dest = (char *) NULL;
- d89 4
- a92 4
- for (bp = *argv; *bp; *bp++) {
- if (*bp == '@@')
- dest = bp;
- }
- d94 3
- a96 3
- if (!dest)
- done(ERR_DATAERR,
- "pathsend: <%s> - badly formed address (no '@@')\n",*argv);
- d98 5
- a102 1
- *dest++ = '\0';
- a103 9
- sprintf(buf, "%s", dest);
- key.dptr = buf;
- key.dsize = strlen(buf) + 1;
- content = fetch(key);
-
- if (content.dptr == 0)
- sprintf(buf,"%s!%s",dest,user);
- else
- sprintf(buf, content.dptr, user);
- d153 13
- @
-